<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            width: 800px;
            margin-left: auto;
            margin-right: auto;
        }
        
        button {
            width: 300px;
            margin-bottom: 10px;
        }
        
        #btnList {
            float: left;
        }
        
        #total {
            width: 450px;
            float: left;
        }
        
        ul {
            list-style-type: none;
            margin: 0px;
            padding: 0px;
        }
        
        .inner li {
            border-style: solid;
            border-width: 1px;
            padding: 5px;
            margin: 5px;
            background-color: #99ff99;
            float: left;
        }
        
        .inner {
            width: 400px;
            border-style: solid;
            border-width: 1px;
            margin-bottom: 10px;
            padding: 10px;
            float: left;
        }
    </style>
</head>

<body>
    <div id="total">
        <div class="inner">
            <p>
                你喜欢哪个城市?
            </p>

            <ul id="city">
                <li id="bj">北京</li>
                <li>上海</li>
                <li>东京</li>
                <li>首尔</li>
            </ul>

        </div>
    </div>
    <div id="btnList">
        <div><button id="btn01">创建一个"广州"节点,添加到#city下</button></div>
        <div><button id="btn02">将"广州"节点插入到#bj前面</button></div>
        <div><button id="btn03">使用"广州"节点替换#bj节点</button></div>
        <div><button id="btn04">删除#bj节点</button></div>
        <div><button id="btn05">读取#city内的HTML代码</button></div>
        <div><button id="btn06">设置#bj内的HTML代码</button></div>
        <div><button id="btn07">创建一个"广州"节点,添加到#city下</button></div>
    </div>

    <script>
        btn01.onclick = function() {
            let li = document.createElement("li");
            li.innerHTML = "广州";
            city.appendChild(li)
        }
        btn02.onclick = function() {
            let li = document.createElement("li");
            li.innerHTML = "广州";
            // bj.before(li)
            city.insertBefore(li, bj)
        }
        btn03.onclick = function() {
            let li = document.createElement("li");
            li.innerHTML = "广州";
            city.replaceChild(li, bj)
        }

        btn04.onclick = function() {
            city.removeChild(bj)
        }

        btn05.onclick = function() {
            console.log(city.innerHTML)
        }
        btn06.onclick = function() {
            bj.innerHTML = "太原"
        }
    </script>
</body>

</html>